package activity

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/activityinfo"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddActivityLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 新增
func NewAddActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddActivityLogic {
	return &AddActivityLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddActivityLogic) AddActivity(req *types.AddActivityInfoReq) (resp *types.Empty, err error) {
	u, err := l.svcCtx.SettingService.Activity.AddActivityInfo(l.ctx, &activityinfo.AddActivityInfoReq{
		MerchantId:  1,                          // 商户ID
		Title:       req.Title,                  // 活动标题
		JumpType:    req.JumpType,               // 跳转方式,1:图片
		Status:      rpc.StatusType(req.Status), // 状态0:关闭,1:开启
		Cover:       req.Cover,                  // 封面图片
		ActivityPic: req.ActivityPic,            // 活动图
		Sort:        req.Sort,                   // 排序
	})

	if err != nil {
		logc.Error(l.ctx, "AddActivity err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	return
}
